/**
 * mem_stream.h
 *
 *  Created on: 2019-09-05
 *      Author: chenshisheng
 */

#ifndef STREAM_MEM_STREAM_H_
#define STREAM_MEM_STREAM_H_

#include "stream/stream.h"

typedef struct
{
    Stream_t stream;
    unsigned char *buffer;
    unsigned int size;
    unsigned int eos;
    unsigned int offset;
}MemStream_t;

int MemStream_Init(MemStream_t *ms, void *buf, unsigned int size);

static inline void MemStream_DeInit(MemStream_t *ms)
{
    Stream_DeInit(& ms->stream);
}

static inline void MemStream_Reset(MemStream_t *ms)
{
    ms->eos = 0;
    ms->offset = 0;
}

static inline unsigned int MemStream_DataSize(MemStream_t *ms)
{
    return ms->eos - ms->offset;
}

static inline unsigned int MemStream_Space(MemStream_t *ms)
{
    return ms->size - ms->eos;
}

static inline void *MemStream_Data(MemStream_t *ms)
{
    return ms->buffer + ms->offset;
}

#endif /* STREAM_MEM_STREAM_H_ */
